<!-- NewPracticeCompanySearchList_frame.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>企业列表信息frame</title>
    <link rel="stylesheet" href="../../css/api.css" />
	<link rel="stylesheet" href="../../css/mui.min.css"/>
	<link rel="stylesheet" href="../../css/base.css"/>
	<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
	<link rel="stylesheet" href="../../css/newPractice.css">
	<style type="text/css">
		.content-div{
			padding: 0 14px;
		}
		.content-cell{
			border-radius: 10px;
			overflow: hidden;
			margin-bottom: 10px;
		}
		.cell-bottom-div{
			background-color: white;
			padding: 10px;
		}
		.right-tag{
			font-size: 12px;
			line-height: 12px;
			padding: 4px 8px;
			color: white;
			border-radius: 4px;
			position: absolute;
			top: 10px;
			right: 20px;
			transform: scale(0.8,0.8);
		}
		.uncollect-tag{
			background-color: #44a6d6;
		}
		.collect-tag{
			background-color: #5bc432;
		}
		.content-cell .hot-news-title-img {
			width: 16px;
		}
		.post-tag{
			padding: 4px 10px;
			border: 1px solid #44a6d6;
			color: #44a6d6;
			font-size: 12px;
			line-height: 12px;
			border-radius: 10px;
			margin-right: 6px;
			margin-bottom: 6px;
		}
		.hot-news-title{
			position: relative;
		}
		.company-tag{
			float: right;
		}
		.sub-tag-div{
			display: inline;
			width: 50px;
			height: 18px;
			transform: rotate(45deg);
			position: absolute;
			top: -1px;
			right: -17px;
			background-color: #44a6d6;
		}
		.sub-tag-span{
			font-size: 12px;
			color: white;
			height: 14px;
			width: 50px;
			line-height: 14px;
			text-align: center;
			transform: scale(0.6);
			position: absolute;
			bottom: 0;
		}
	</style>
</head>
<body>
	<div id="tableview" class="content-div">
		<!-- <div class="content-cell">
			<div class="hot-news-title">
				<img src="../../image/icon_06.png" alt="" class="hot-news-title-img">
				<span class="base_dark_grey_shallow base_title_font hot-news-title-span">
					轮岗岗位
				</span>
				<span class="right-tag uncollect-tag">
					未收藏
				</span>
			</div>
			<div class="cell-bottom-div mui-table-view">
				<span class="post-tag">
					运输规划
				</span>
				<span class="post-tag">
					运输规划
				</span>
				<span class="post-tag">
					运输规划
				</span>
				<span class="post-tag">
					运输规划
				</span>
			</div>	
		</div> -->
		<!-- <div class="content-cell">
			<div class="hot-news-title">
				<img src="../../image/icon_06.png" alt="" class="hot-news-title-img">
				<span class="base_dark_grey_shallow base_title_font hot-news-title-span">
					轮岗岗位
				</span>
				<span class="post-tag company-tag">
					运输规划
				</span>
			</div>
		</div> -->
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
				重新加载
			</button>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
	var page = 1;
	var rows = 10;
	var keyword = "";
	var currentType = 0;
	var dropRefreshCount = 0;
	var companyArr = new Array();
	var postArr = new Array();
	var currentPost = null;
	apiready = function(){
	    prepareData();
		setupNotifi();
		setRefreshHeader();
		setPullUpRefresh();
	}
	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			refreshData();
		});
	}
	// 上拉加载
	function setPullUpRefresh() {
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (dropRefreshCount >= rows) {
				dropRefreshCount = 0;
				page++;
				loadSearchData();
			}
		});
	}
	function prepareData(){
		var pageParam = api.pageParam;
		currentType = pageParam.type;
	}
	function setupNotifi(){
		api.addEventListener({
		    name: 'searchPracticeNotifi'
		}, function(ret, err) {
		    if (ret) {
		        var value = ret.value;
		        var type = value.type;
		        if (type != currentType) {
		        	return;
		        }
		        keyword = value.keyword;
		        loadSearchData();
		    }
		});
		api.addEventListener({
		    name: 'practiceApplySucceedNotifi'
		}, function(ret, err) {
		    if (currentPost != null) {
		    	var postData = ret.value;
		    	var postid = postData.id;
		    	if (postid == currentPost.id) {
		    		currentPost.apply_status = 1;
		    		$('#'+postid).append(applyTagHtml());
		    	}
		    }
		});
	}
	function refreshData(){
		page = 1;
		loadSearchData();
	}
	function loadSearchData(){
		var params = {
			page : page,
			rows : rows,
			keyword : keyword,
			type : currentType,
			uid : $api.getStorage('cfnetppuid')
		};
		if (page == 1) {
			api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '数据加载中...',
			    text: '',
			    modal: false
			});
		}
		cfnetppPOST(url_newPracticeSearch, params, true, function(data, status){
			api.refreshHeaderLoadDone();
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					if (page == 1) {
						companyArr = new Array();
						postArr = new Array();
						$('#tableview').html('');
					}
					$('#noData').hide();
					$('#noNet').hide();
					var jsonData = data.data;
					setupSearchData(jsonData);
				}else{
					api.toast({
					    msg: data.message
					});
					if (page == 1) {
						$('#tableview').html('');
						$('#noData').show();
						$('#noNet').hide();
					}
				}
			}else{
				api.toast({
				    msg: '网络异常'
				});
				if (page == 1) {
					$('#tableview').html('');
					$('#noData').hide();
					$('#noNet').show();
				}
			}
		});
	}
	function setupSearchData(jsonData){
		if (currentType == 0) {
			var company_list = jsonData.company_list;
			setupCompanyData(company_list);
		}else{
			var post_list = jsonData.post_list;
			setupPostData(post_list);
		}
	}
	function setupCompanyData(arr){
		dropRefreshCount = arr.length;
		if (arr.length > 0) {
			var oldCount = companyArr.length;
			companyArr = companyArr.concat(arr);
			var newCount = companyArr.length;
			for (var i = oldCount; i < newCount; i++) {
				var company  = companyArr[i];
				$('#tableview').append(searchCompanyCellHtml(i, company));
			}
			setupCompanyCellClick();
		}else{
			if (page == 1) {
				api.toast({
				    msg: '未搜索到该企业'
				});
				$('#noData').show();
				$('#noNet').hide();
			}
		}
	}
	function setupCompanyCellClick(){
		$('.company-cell').unbind('click');
		$('.company-cell').click(function(){
			var index = $(this).attr('index');
			var companyData = companyArr[parseInt(index)];
			api.openWin({useWKWebView:true,
			    name: 'NewPracticeCompanyDetail_win',
			    url: 'NewPracticeCompanyDetail_win.html',
			    pageParam: {
			    	id : companyData.companyid
			    }
			});
		});
	}
	function setupPostData(arr){
		dropRefreshCount = arr.length;
		if (arr.length > 0) {
			var oldCount = postArr.length;
			postArr = postArr.concat(arr);
			var newCount = postArr.length;
			for (var i = oldCount; i < newCount; i++) {
				var post  = postArr[i];
				$('#tableview').append(searchPostCellHtml(i, post));
			}
			setupPostCellClick();
		}else{
			if (page == 1) {
				api.toast({
				    msg: '未搜索到该岗位'
				});
				$('#noData').show();
				$('#noNet').hide();
			}
		}
	}
	function setupPostCellClick(){
		$('.post-cell').unbind('click');
		$('.post-cell').click(function(){
			var index = $(this).attr('index');
			var postData = postArr[parseInt(index)];
			if (postData.apply_status == 1) {
				api.toast({
				    msg: '已申请该岗位，请耐心等待工作人员联系'
				});
				return;
			}
			currentPost = postData;
			api.openWin({useWKWebView:true,
			    name: 'NewPracticeApply_win',
			    url: 'NewPracticeApply_win.html',
			    pageParam: postData
			});
		});
	}
	function searchPostCellHtml(index, data){
		var post_name = data.post_name;
		var postid = data.id;
		var bizs = data.bizs;
		var companyname = bizs.names;
		var apply_status = data.apply_status;
		var applyHtml = '';
		if (apply_status == 1) {
			applyHtml = applyTagHtml();
		}
		return '<div index="'+index+'" class="content-cell post-cell">\
					<div id="'+postid+'" class="hot-news-title">\
						<img src="../../image/icon_06.png" alt="" class="hot-news-title-img">\
						<span class="base_dark_grey_shallow base_title_font hot-news-title-span">'+
							post_name+
						'</span>\
						<span class="post-tag company-tag">'+
							companyname+
						'</span>'+
						applyHtml+
					'</div>\
				</div>';
	}
	function applyTagHtml(){
		return '<div class="sub-tag-div">'+
					'<span class="sub-tag-span">'+
						'已申请'+
					'</span>'+
				'</div>';
	}
	function searchCompanyCellHtml(index, data){
		var company_name = data.company_name;
		var postHtml = '';
		var post_list = data.post_list;
		if (post_list.length > 0) {
			postHtml = postDivHtml(post_list);
		}
		return '<div index="'+index+'" class="content-cell company-cell">\
					<div class="hot-news-title">\
						<img src="../../image/icon_06.png" alt="" class="hot-news-title-img">\
						<span class="base_dark_grey_shallow base_title_font hot-news-title-span">'+
							company_name+
						'</span>\
					</div>'+
					postHtml+
				'</div>';
	}
	function postDivHtml(postArr){
		var postCellsHtml = '';
		for (var i = 0; i < postArr.length; i++) {
			var postData = postArr[i];
			postCellsHtml += postCellHtml(postData);
		}
		return '<div class="cell-bottom-div mui-table-view">'+
					postCellsHtml+
				'</div>';
	}
	function postCellHtml(postData){
		var postName = postData.post_name;
		var postid = postData.postid;
		return '<span id="'+postid+'" class="post-tag">'+
					postName+	
				'</span>';
	}
</script>
</html>